package net.nagaseyasuhito.kinsenka.wicket.page;

import java.util.List;

import net.nagaseyasuhito.kinsenka.persist.dao.TaskDao;
import net.nagaseyasuhito.kinsenka.persist.entity.Task;
import net.nagaseyasuhito.kinsenka.wicket.KinsenkaSession;
import net.nagaseyasuhito.kinsenka.wicket.component.TaskColumn;
import net.nagaseyasuhito.kinsenka.wicket.util.EntityProvider;

import org.apache.wicket.authroles.authorization.strategies.role.Roles;
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.markup.html.link.Link;

import com.google.common.collect.Lists;

@AuthorizeInstantiation(Roles.USER)
public class IndexPage extends BasePage {
	private static final long serialVersionUID = 1L;

	public IndexPage() {
		this.add(new Link<Void>("createTask") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick() {
				Task task = new Task();
				task.setUser(KinsenkaSession.get().getUser());

				this.setResponsePage(new ModifyTaskPage(task));
			}
		});

		Task criteria = new Task();

		List<IColumn<Task>> columns = Lists.newArrayList();
		columns.add(new TaskColumn());

		this.add(new AjaxFallbackDefaultDataTable<Task>("tasks", columns, new EntityProvider<Task>(criteria, TaskDao.class, "updateTimestamp", false), 10));
	}
}
